package org.flower.dao.impl;

import org.flower.dao.FloorDao;
import org.flower.entity.Floor;
import org.flower.utils.BaseDao;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 楼层接口实现
 */
public class FloorDaoImpl extends BaseDao implements FloorDao {

    //根据楼层编号获取楼层信息
    @Override
    public Floor getFloorById(int id) {
        Floor floor = null;
        String sql = "select * from `floor` where id=?";
        ResultSet rs = super.executeQuery(sql, id);
        try {
            if(rs.next()){
                floor = new Floor();
                floor.setId(rs.getInt("id"));
                floor.setTitle(rs.getString("title"));
                floor.setRemark(rs.getString("remark"));
                floor.setImage(rs.getString("image"));
                floor.setCommId(rs.getInt("commId"));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            try {
                super.closeAll(rs,rs.getStatement(),rs.getStatement().getConnection());
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        return floor;
    }
}
